package com.emm.yixun.common.utils;

import org.apache.http.HttpEntity;  
import org.apache.http.HttpResponse;  
import org.apache.http.client.HttpClient;  
import org.apache.http.client.methods.HttpPost;  
import org.apache.http.entity.StringEntity;  
import org.apache.http.util.EntityUtils;   
import com.alibaba.fastjson.JSONObject;
import java.net.URLEncoder;
 

/**
 * 第一信息短信网关的初级封装
 */
public final class NameCheckUtil {
	private static String doPost(String url, String jsonStr, String charset){
		HttpClient httpClient = null;
		HttpPost httpPost = null;
		String result = null;
		try{
			httpClient = new SSLClient();		//一般用法
			httpPost = new HttpPost(url);			
			StringEntity entity = new StringEntity(URLEncoder.encode(jsonStr,charset));
			httpPost.setEntity(entity);			
			HttpResponse response = httpClient.execute(httpPost);
			if(response != null){
				HttpEntity resEntity = response.getEntity();
				if(resEntity != null){
					result = EntityUtils.toString(resEntity,charset);
				}
			}
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return result;
	}
	
	
	
    public static void main(String[] args) {
		JSONObject param=new JSONObject(); 
		param.put("idCard", "320743199101175520");
		param.put("name", "李丙付");
		JSONObject res = new JSONObject();
		//生产：yixun2016 yi2016xun
		res.put("loginName", "test");
		res.put("pwd", "123456");
		res.put("serviceName", "IDNameCheck");
		res.put("param", param);
		//生产：https://www.miniscores.cn:8314/CreditFunc
		String url="https://114.55.36.16:8090/CreditFunc";
		String result=doPost(url,res.toJSONString(),"utf-8");
		System.out.print(result);
	}
  
}
